package com.weiweiqin.controller.back;

import com.weiweiqin.model.Integrallog;
import com.weiweiqin.service.IntegrallogService;
import com.weiweiqin.vo.common.IntegrallogTabVO;
import com.weiweiqin.vo.common.Page;
import com.weiweiqin.vo.common.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("admin/integrallog")
public class IntegrallogController {

	@Autowired
	private IntegrallogService integrallogService;

	private static final Logger logger = LoggerFactory
			.getLogger(IntegrallogController.class);

	@RequestMapping(value = "/pageList.do", method = { RequestMethod.POST,
			RequestMethod.GET })
	@ResponseBody
	public String pageList(int currPage){
		Result result = new Result();
		Page page = new Page();
		page.setCurrPage(currPage);
		Map<String,Object> conditions = new HashMap<String, Object>();
		List<Integrallog> integrallogList = integrallogService.pageList(page, conditions);

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");

		List<IntegrallogTabVO> voList = new ArrayList<IntegrallogTabVO>();
		if(null != integrallogList && !integrallogList.isEmpty()){
			for (Integrallog paylog : integrallogList) {
				IntegrallogTabVO vo = new IntegrallogTabVO();
				vo.setIntegrallog(paylog);
				String format = sdf.format(paylog.getCreateTime());
				vo.setCreateTime(format);
				voList.add(vo);
			}
		}
		int totalCount = integrallogService.totalCount(conditions);
		page.setTotalCount(totalCount);
		Map<String,Object> mp = new HashMap<String,Object>();
		mp.put("totalCount",page.getTotalCount());
		mp.put("list", voList);
		result.setObj(mp);
		result.setResult(true);
		return result.toJson();
	}

}
